package com.fas.system.service.impl;

import com.fas.common.core.domain.AjaxResult;
import com.fas.system.domain.FasFacilitiesTypeDataItem;
import com.fas.system.mapper.FasFacilitiesTypeDataItemMapper;
import com.fas.system.service.IFasFacilitiesTypeDataItemService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FasFacilitiesTypeDataItemServiceImpl implements IFasFacilitiesTypeDataItemService {

    @Resource
    private FasFacilitiesTypeDataItemMapper fasFacilitiesTypeDataItemMapper;


    @Override
    public List<FasFacilitiesTypeDataItem> findByFacilityId(FasFacilitiesTypeDataItem fasFacilitiesTypeDataItem) {
        return fasFacilitiesTypeDataItemMapper.findByFacilityId(fasFacilitiesTypeDataItem);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult addFasFacilitiesTypeDataItem(FasFacilitiesTypeDataItem fasFacilitiesTypeDataItem) {
        String itemContent = fasFacilitiesTypeDataItem.getItemContent();
        int exists = fasFacilitiesTypeDataItemMapper.existsItemContent(itemContent);
        if(exists > 0) {
            return AjaxResult.error("数据项内容已存在，请重新输入");
        }
        int count = fasFacilitiesTypeDataItemMapper.addFasFacilitiesTypeDataItem(fasFacilitiesTypeDataItem);
        return count > 0 ? AjaxResult.success(): AjaxResult.error();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int editFasFacilitiesTypeDataItem(FasFacilitiesTypeDataItem fasFacilitiesTypeDataItem) {
        return fasFacilitiesTypeDataItemMapper.editFasFacilitiesTypeDataItem(fasFacilitiesTypeDataItem);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteFasFacilitiesTypeDataItem(String id) {
        return fasFacilitiesTypeDataItemMapper.deleteFasFacilitiesTypeDataItem(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int enableDataItem(FasFacilitiesTypeDataItem fasFacilitiesTypeDataItem) {
        return fasFacilitiesTypeDataItemMapper.enableDataItem(fasFacilitiesTypeDataItem);
    }
}
